local cid = arg[1] or "111";
local host, port = "127.0.0.1", 8080
local socket = require("socket")
local cjson = require("cjson")
local tcp = assert(socket.tcp())

data = [[
{"sender":"client","msgtype":"asrequest","cid":"_cid_", "data":"xxx.wav"}
]]

sendIds = {}
recvIds = {}

sendCount = 0
recvCount = 0;

for i=1, 100 do
	sendCount = sendCount + 1;
	local mcid = cid .. "_" .. i;
	tcp:connect(host, port);
	local sdata = string.gsub(data, "_cid_", mcid);
	--note the newline below
	print(">>>>>send:" .. sdata)
	tcp:send(sdata);
	table.insert(sendIds, mcid)
end

print("start to receive:")
for i=1,100 do
	local recvMsg, status, partial = tcp:receive()
	recvCount = recvCount + 1;
	print("<<<<<receive:" .. (recvMsg or ""))
	local rm = cjson.decode(recvMsg);
	table.insert(recvIds, rm["tocid"])
end

tcp:close()
print("send:" .. sendCount .. ", receive:" .. recvCount)
